package services

import (
	"goravel/app/models"

	"github.com/goravel/framework/facades"
)

type UserService struct {
}

func NewUserService() *UserService {
	return &UserService{
		//Inject services
	}
}

// first record
func (r *UserService) First() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().First(&user); err != nil {
		return user, err
	}

	return user, nil
}

// 根据ID查找
func (r *UserService) FindById(id int32) (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().Find(&user, id); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) Find() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) getLists() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) lists() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) Create() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) BatchCreate() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) Update() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) BatchUpdate() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) Delete() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) DeleteById() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) BatchDelete() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) Count() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) Sum() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}

func (r *UserService) RunSql() (models.User, error) {
	var user models.User

	if err := facades.Orm().Query().FindOrFail(&user); err != nil {
		return user, err
	}

	return user, nil
}
